package training_camp.day1.leetcode35;

class Solution {
    public int searchInsert(int[] nums, int target) {
        int n = nums.length;
        int l =0 ;
        int r = n-1;
        while(l<=r){
            int mid = l+ (r-l)/2;
            if (nums[mid]>target){
                r = mid -1;
            }
            else if (nums[mid]<target){
                l = mid+1;
            }
            else {
                r = mid-1;
            }
        }
        return  r +1;
    }
}